import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:search_people/page/home/subs/person_detail/models/person_dynamic_model.dart';
import 'package:search_people/utils/component/tag.dart';
import 'package:search_people/utils/img_util.dart';
import 'package:search_people/utils/util.dart';
import 'package:search_people/value/topcolors.dart';
import 'package:url_launcher/url_launcher_string.dart';

class DynamicCell extends StatelessWidget {
  const DynamicCell({
    Key? key,
    required this.md,
  }) : super(key: key);
  final PersonDynamicModel md;
  Widget _buildItemView({
    required String key,
    required String val,
    Function()? onTap,
  }) {
    return RichText(
      text: TextSpan(
          text: key,
          style: TextStyle(
            color: TopColors.black_99,
            fontSize: 10.r,
          ),
          children: [
            TextSpan(
                text: val,
                style: TextStyle(
                  color: TopColors.main_color,
                  fontSize: 10.r,
                ),
                recognizer: TapGestureRecognizer()..onTap = onTap)
          ]),
    );
  }

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () {
        launchUrlString(md.link ?? '');
      },
      child: Container(
        color: Colors.white,
        padding: EdgeInsets.symmetric(horizontal: 18.r, vertical: 15.r),
        child: Column(
          children: [
            Text(
              md.title ?? '',
              style: TextStyle(
                color: TopColors.black_33,
                fontSize: 14.sp,
              ),
            ),
            Container(
              padding: EdgeInsets.symmetric(vertical: 10.r),
              alignment: Alignment.centerLeft,
              child: TagView(
                titles: md.labelList ?? [],
                colors:
                    md.labelColors ?? [Colors.green, Colors.red, Colors.purple],
              ),
            ),
            Text(
              md.overview ?? '',
              style: TextStyle(color: TopColors.black_33, fontSize: 11.sp),
              maxLines: 2,
              overflow: TextOverflow.ellipsis,
            ),
            // SizedBox(
            //   height: 10.r,
            // ),
            // Wrap(
            //   spacing: 10.r,
            //   children: [
            //     'https://cms-emer-res.cctvnews.cctv.com/image/3003/process/93ae44156b6345158680ceac3f745e5c.png',
            //     'https://cms-emer-res.cctvnews.cctv.com/image/3003/process/661faf61d4854c57b16fa9644beb45af.png',
            //     'https://p5.img.cctvpic.com/photoAlbum/photo/2023/01/28/PHOTRcF0Gf6mAhCFVxsoRfdG230128_1000x2000.jpg',
            //   ]
            //       .map((e) => loadImage(
            //           url: e,
            //           width: (Get.width - 44.r) / 3,
            //           height: (Get.width - 44.r) / 3 * 0.75))
            //       .toList(),
            // ),
            SizedBox(
              height: 10.r,
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    md.hasLinkPerson
                        ? _buildItemView(
                            key: '相关人物：',
                            val: md.name ?? '',
                            onTap: () {
                              Get.toNamed(RouterPath.person_detail,
                                  arguments: md.leaderBaseinfoId);
                            },
                          )
                        : const SizedBox(),
                    SizedBox(
                      width: md.hasLinkPerson ? 15.r : 0,
                    ),
                    _buildItemView(
                      key: '信息来源：',
                      val: md.source ?? '',
                      onTap: () {
                        Get.log('腾讯网');
                      },
                    ),
                  ],
                ),
                Text(
                  md.releaseTime ?? '',
                  style: TextStyle(
                    color: TopColors.black_99,
                    fontSize: 10.r,
                  ),
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}
